home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / chewits.swf / scripts / frame_2 / PlaceObject2_148_74 / CLIPACTIONRECORD onClipEvent(enterFrame).as next >
Encoding:
Text File  |  2008-11-13  |  21.5 KB  |  533 lines

  1. onClipEvent(enterFrame){
  2.    var INITIAL_HIT_BOUNCE_DELTA_Y = 8;
  3.    var BOUNCE_DROP_SPEED = -1.8;
  4.    switch(_parent.gamestate)
  5.    {
  6.       case GAMESTATE_PAUSED:
  7.          grabtime();
  8.          if(!Key.isDown(32) && !Key.isDown(80))
  9.          {
  10.             _parent.gamestate = GAMESTATE_PAUSED_WAIT;
  11.          }
  12.          break;
  13.       case GAMESTATE_PAUSED_WAIT:
  14.          grabtime();
  15.          if(Key.isDown(32) || Key.isDown(80))
  16.          {
  17.             _parent.gamestate = GAMESTATE_PLAYING_WAIT;
  18.             mouse.hide();
  19.          }
  20.          break;
  21.       case GAMESTATE_PLAYING:
  22.       case GAMESTATE_PLAYING_WAIT:
  23.          timeinstate += _parent.delta;
  24.          grabtime();
  25.          var a = 0;
  26.          while(a < animations.length)
  27.          {
  28.             animations[a][ANIMATION_FRAMETIME] += _parent.delta * animations[a][ANIMATION_SPEED];
  29.             if(animations[a][ANIMATION_FRAMETIME] > 1)
  30.             {
  31.                animations[a][ANIMATION_CURRENT_FRAME]++;
  32.                if(animations[a][ANIMATION_CURRENT_FRAME] > animations[a][ANIMATION_END_FRAME])
  33.                {
  34.                   animations[a][ANIMATION_CURRENT_FRAME] = animations[a][ANIMATION_START_FRAME];
  35.                }
  36.                animations[a][ANIMATION_FRAMETIME] -= 1;
  37.             }
  38.             a++;
  39.          }
  40.          if(chewystate == CHEWY_STATE_FIRING)
  41.          {
  42.             var a = FIRE_IDLE_ANIMATION;
  43.             while(a <= FIRE_WALK_ANIMATION)
  44.             {
  45.                animations[a][ANIMATION_FRAMETIME] += _parent.delta;
  46.                if(animations[a][ANIMATION_FRAMETIME] > 1)
  47.                {
  48.                   animations[a][ANIMATION_CURRENT_FRAME]++;
  49.                   if(animations[a][ANIMATION_CURRENT_FRAME] > animations[a][ANIMATION_END_FRAME])
  50.                   {
  51.                      timeinstate = 0;
  52.                      chewystate = CHEWY_STATE_OK;
  53.                      animations[a][ANIMATION_CURRENT_FRAME] = animations[a][ANIMATION_START_FRAME];
  54.                   }
  55.                   animations[a][ANIMATION_FRAMETIME] = 0;
  56.                }
  57.                a++;
  58.             }
  59.          }
  60.          var CHEW_TIME = 12;
  61.          if(chewystate == CHEWY_STATE_CHEWING && timeinstate > CHEW_TIME)
  62.          {
  63.             timeinstate = 0;
  64.             chewystate = CHEWY_STATE_OK;
  65.          }
  66.          switch(chewystate)
  67.          {
  68.             case CHEWY_STATE_OK:
  69.             case CHEWY_STATE_CHEWING:
  70.             case CHEWY_STATE_FIRING:
  71.                var b = 0;
  72.                while(b < MAX_BAGS)
  73.                {
  74.                   if(_parent["bag" + b]._visible)
  75.                   {
  76.                      if(_parent["bag" + b].canhitchewy && bagcollison(b))
  77.                      {
  78.                         play_chewyhitbybag_sound();
  79.                         chewystate = CHEWY_STATE_HIT;
  80.                         var CHEWY_BOUNCE_DELTA_X = 6;
  81.                         if(_parent["bag" + b]._x > _X)
  82.                         {
  83.                            chewy_facing = CHEWY_FACING_LEFT;
  84.                            delta_x = - CHEWY_BOUNCE_DELTA_X;
  85.                         }
  86.                         else
  87.                         {
  88.                            chewy_facing = CHEWY_FACING_RIGHT;
  89.                            delta_x = CHEWY_BOUNCE_DELTA_X;
  90.                         }
  91.                         delta_y = INITIAL_HIT_BOUNCE_DELTA_Y;
  92.                         initial_delta_y = INITIAL_HIT_BOUNCE_DELTA_Y;
  93.                         bounce_speed = BOUNCE_DROP_SPEED;
  94.                         timeinstate = 0;
  95.                         _parent["bag" + b]._visible = false;
  96.                         nobags--;
  97.                         lives--;
  98.                         if(lives >= 0)
  99.                         {
  100.                            _parent["life" + lives]._visible = false;
  101.                         }
  102.                         var b2 = 0;
  103.                         while(b2 < MAX_BAGS)
  104.                         {
  105.                            if(_parent["bag" + b2]._visible)
  106.                            {
  107.                               _parent["bag" + b2].canhitchewy = false;
  108.                            }
  109.                            b2++;
  110.                         }
  111.                      }
  112.                      var FLAME_WIDTH = 9;
  113.                      var f = 0;
  114.                      while(f < MAX_FLAMES)
  115.                      {
  116.                         if(_parent["flame" + f]._visible)
  117.                         {
  118.                            if(_parent["bag" + b].hittest(_parent["flame" + f]._x - FLAME_WIDTH,_parent["flame" + f]._y) || _parent["bag" + b].hittest(_parent["flame" + f]._x + FLAME_WIDTH,_parent["flame" + f]._y))
  119.                            {
  120.                               play_baghitbyfireball_sound();
  121.                               var TOP_TIME = 10;
  122.                               var distancescale = _parent["flame" + f].flametime / TOP_TIME;
  123.                               if(distancescale > 1)
  124.                               {
  125.                                  distancescale = 1;
  126.                               }
  127.                               throwchewits(b,distancescale);
  128.                               _parent["bag" + b]._visible = false;
  129.                               _parent["flame" + f]._visible = false;
  130.                               nobags--;
  131.                            }
  132.                         }
  133.                         f++;
  134.                      }
  135.                   }
  136.                   b++;
  137.                }
  138.                nextflametime -= _parent.delta;
  139.                var REENABLE_BAGS_TIME = 12;
  140.                if(timeinstate > REENABLE_BAGS_TIME && timeinstate < REENABLE_BAGS_TIME + 0.3)
  141.                {
  142.                   var b = 0;
  143.                   while(b < MAX_BAGS)
  144.                   {
  145.                      if(!_parent["bag" + b].canhitchewy)
  146.                      {
  147.                         _parent["bag" + b].canhitchewy = true;
  148.                      }
  149.                      b++;
  150.                   }
  151.                }
  152.                var desired_x = _parent._xmouse;
  153.                MOVERATE = 15;
  154.                if(_X <= desired_x)
  155.                {
  156.                   if(desired_x > MAX_X - CHEWY_WIDTH / 2)
  157.                   {
  158.                      desired_x = MAX_X - CHEWY_WIDTH / 2;
  159.                   }
  160.                   _X = _X + MOVERATE * _parent.delta;
  161.                   if(_X >= desired_x)
  162.                   {
  163.                      _X = desired_x;
  164.                   }
  165.                }
  166.                if(_X > desired_x)
  167.                {
  168.                   if(desired_x < MIN_X + CHEWY_WIDTH / 2)
  169.                   {
  170.                      desired_x = MIN_X + CHEWY_WIDTH / 2;
  171.                   }
  172.                   _X = _X - MOVERATE * _parent.delta;
  173.                   if(_X < desired_x)
  174.                   {
  175.                      _X = desired_x;
  176.                   }
  177.                }
  178.                var MOUTHDISTANCE_X = 12;
  179.                var MOUTHDISTANCE_Y = 24;
  180.                var mouthposition_x = _X;
  181.                var mouthposition_y = _Y - MOUTHDISTANCE_Y - CHEWY_Y_ADJUST;
  182.                if(chewyfacing == CHEWY_FACING_LEFT)
  183.                {
  184.                   mouthposition_x -= MOUTHDISTANCE_X;
  185.                }
  186.                else
  187.                {
  188.                   mouthposition_x += MOUTHDISTANCE_X;
  189.                }
  190.                var onesuckedin = 0;
  191.                var c = 0;
  192.                while(c < MAX_CHEWITS)
  193.                {
  194.                   if(_parent["chewit" + c]._visible)
  195.                   {
  196.                      if(_parent["chewit" + c].suckedin)
  197.                      {
  198.                         _parent["chewit" + c].sucktime += _parent.delta;
  199.                         onesuckedin = 1;
  200.                         _parent["chewit" + c]._x += mouthposition_x - _parent["chewit" + c].last_mx;
  201.                         _parent["chewit" + c]._y += mouthposition_y - _parent["chewit" + c].last_my;
  202.                      }
  203.                      var dist_x = mouthposition_x - _parent["chewit" + c]._x;
  204.                      var dist_y = mouthposition_y - _parent["chewit" + c]._y;
  205.                      var thisdistance = dist_x * dist_x + dist_y * dist_y;
  206.                      if(_parent["chewit" + c].suckedin)
  207.                      {
  208.                         var MOVE_SCALE = 0.4;
  209.                         _parent["chewit" + c]._x += dist_x * _parent.delta * MOVE_SCALE;
  210.                         _parent["chewit" + c]._y += dist_y * _parent.delta * MOVE_SCALE;
  211.                         _parent["chewit" + c].last_mx = mouthposition_x;
  212.                         _parent["chewit" + c].last_my = mouthposition_y;
  213.                         _parent["chewit" + c]._rotation += _parent["chewit" + c].rotaterate * _parent.delta;
  214.                         var scalechew = CHEWIT_SCALE * thisdistance / _parent["chewit" + c].suck_distance;
  215.                         if(scalechew > CHEWIT_SCALE)
  216.                         {
  217.                            scalechew = CHEWIT_SCALE;
  218.                         }
  219.                         _parent["chewit" + c]._xscale = scalechew;
  220.                         _parent["chewit" + c]._yscale = scalechew;
  221.                         var MAX_SUCK_TIME = 2;
  222.                         if(scalechew < 4 || _parent["chewit" + c].sucktime < MAX_SUCK_TIME)
  223.                         {
  224.                            play_chewyeatsachewit_sound();
  225.                            var points = getpoints();
  226.                            var combono = 0;
  227.                            var c2 = 0;
  228.                            while(c2 < MAX_CHEWITS)
  229.                            {
  230.                               if(c != c2 && _parent["chewitscore" + c2]._visible && !_parent["chewitscore" + c2].bombshot)
  231.                               {
  232.                                  combono++;
  233.                               }
  234.                               c2++;
  235.                            }
  236.                            score += points * (1 + combono);
  237.                            addchewitscore(c,points * (1 + combono),combono);
  238.                            updatescore(score);
  239.                            _parent["chewit" + c]._visible = false;
  240.                            _parent["chewitscore" + c].bombshot = false;
  241.                         }
  242.                      }
  243.                      else
  244.                      {
  245.                         var CHOMP_TOLERANCE_X2 = 1024;
  246.                         var CHOMP_TOLERANCE_Y2 = 144;
  247.                         var distancex = _parent["chewit" + c]._x - mouthposition_x;
  248.                         var distancey = _parent["chewit" + c]._y - mouthposition_y;
  249.                         var distancex2 = distancex * distancex;
  250.                         var distancey2 = distancey * distancey;
  251.                         if(distancex2 < CHOMP_TOLERANCE_X2 && distancey2 < CHOMP_TOLERANCE_Y2)
  252.                         {
  253.                            var SWALLOW_ROTATE_RATE = 10;
  254.                            _parent["chewit" + c].suckedin = true;
  255.                            _parent["chewit" + c].sucktime = 0;
  256.                            _parent["chewit" + c].suck_distance = thisdistance;
  257.                            _parent["chewit" + c].last_mx = mouthposition_x;
  258.                            _parent["chewit" + c].last_my = mouthposition_y;
  259.                            if(_parent["chewit" + c].rotaterate > 0)
  260.                            {
  261.                               _parent["chewit" + c].rotaterate = SWALLOW_ROTATE_RATE;
  262.                            }
  263.                            else
  264.                            {
  265.                               _parent["chewit" + c].rotaterate = - SWALLOW_ROTATE_RATE;
  266.                            }
  267.                            chewystate = CHEWY_STATE_CHEWING;
  268.                            timeinstate = 0;
  269.                         }
  270.                      }
  271.                   }
  272.                   c++;
  273.                }
  274.                WALK_TOLERANCE = 4;
  275.                if(Math.abs(lastwalkpos - _X) > WALK_TOLERANCE)
  276.                {
  277.                   if(lastwalkpos > _X)
  278.                   {
  279.                      chewyfacing = CHEWY_FACING_RIGHT;
  280.                   }
  281.                   else
  282.                   {
  283.                      chewyfacing = CHEWY_FACING_LEFT;
  284.                   }
  285.                   lastwalkpos = _X;
  286.                   if(chewystate == CHEWY_STATE_CHEWING)
  287.                   {
  288.                      this.gotoAndStop(animations[CHEW_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
  289.                   }
  290.                   else if(chewystate == CHEWY_STATE_FIRING)
  291.                   {
  292.                      this.gotoAndStop(animations[FIRE_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
  293.                   }
  294.                   else if(onesuckedin == 1)
  295.                   {
  296.                      this.gotoAndStop(animations[SUCK_WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
  297.                   }
  298.                   else
  299.                   {
  300.                      this.gotoAndStop(animations[WALK_ANIMATION][ANIMATION_CURRENT_FRAME]);
  301.                   }
  302.                }
  303.                else if(chewystate == CHEWY_STATE_CHEWING)
  304.                {
  305.                   this.gotoAndStop(animations[CHEW_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
  306.                }
  307.                else if(chewystate == CHEWY_STATE_FIRING)
  308.                {
  309.                   this.gotoAndStop(animations[FIRE_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
  310.                }
  311.                else if(onesuckedin == 1)
  312.                {
  313.                   this.gotoAndStop(animations[SUCK_IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
  314.                }
  315.                else
  316.                {
  317.                   this.gotoAndStop(animations[IDLE_ANIMATION][ANIMATION_CURRENT_FRAME]);
  318.                }
  319.                break;
  320.             case CHEWY_STATE_HIT:
  321.                this.gotoAndStop(animations[HIT_ANIMATION][ANIMATION_CURRENT_FRAME]);
  322.                delta_y += bounce_speed * _parent.delta;
  323.                _Y = _Y - delta_y * _parent.delta;
  324.                _X = _X + delta_x * _parent.delta;
  325.                if(_X > MAX_X - CHEWY_WIDTH / 2)
  326.                {
  327.                   _X = MAX_X - CHEWY_WIDTH / 2;
  328.                   delta_x = 0;
  329.                }
  330.                if(_X < MIN_X + CHEWY_WIDTH / 2)
  331.                {
  332.                   _X = MIN_X + CHEWY_WIDTH / 2;
  333.                   delta_x = 0;
  334.                }
  335.                if(_Y > base_y)
  336.                {
  337.                   _Y = base_y;
  338.                   initial_delta_y /= 2;
  339.                   if(initial_delta_y > INITIAL_HIT_BOUNCE_DELTA_Y / 16)
  340.                   {
  341.                      delta_y = initial_delta_y;
  342.                   }
  343.                   else
  344.                   {
  345.                      delta_y = 0;
  346.                      bounce_speed = 0;
  347.                   }
  348.                }
  349.                if(timeinstate > HIT_TIME_MAXIMUM)
  350.                {
  351.                   _Y = base_y;
  352.                   _alpha = 100;
  353.                   timeinstate = 0;
  354.                   if(lives < 0)
  355.                   {
  356.                      play_death_sound();
  357.                      _parent.gamestate = GAMESTATE_GAME_OVER_FADE;
  358.                   }
  359.                   else
  360.                   {
  361.                      chewystate = CHEWY_STATE_OK;
  362.                   }
  363.                }
  364.                else
  365.                {
  366.                   var segment = Math.round(timeinstate * 10 / HIT_TIME_MAXIMUM);
  367.                   if(segment % 2 == 1)
  368.                   {
  369.                      _alpha = 0;
  370.                   }
  371.                   else
  372.                   {
  373.                      _alpha = 100;
  374.                   }
  375.                }
  376.          }
  377.          if(chewyfacing == CHEWY_FACING_LEFT)
  378.          {
  379.             _xscale = CHEWY_SCALE;
  380.          }
  381.          else
  382.          {
  383.             _xscale = - CHEWY_SCALE;
  384.          }
  385.          updatebags();
  386.          updatebomb();
  387.          updateflames();
  388.          updatechewits();
  389.          updatefloor();
  390.          if(_parent.gamestate == GAMESTATE_PLAYING)
  391.          {
  392.             if(Key.isDown(32) || Key.isDown(80))
  393.             {
  394.                _parent.gamestate = GAMESTATE_PAUSED;
  395.                mouse.show();
  396.             }
  397.          }
  398.          else if(_parent.gamestate == GAMESTATE_PLAYING_WAIT)
  399.          {
  400.             if(!Key.isDown(32) && !Key.isDown(80))
  401.             {
  402.                _parent.gamestate = GAMESTATE_PLAYING;
  403.             }
  404.          }
  405.          var FLOOR_MAXIMUM_HEIGHT = 130;
  406.          if(base_y < FLOOR_MAXIMUM_HEIGHT)
  407.          {
  408.             if(base_y >= FLOOR_MAXIMUM_HEIGHT)
  409.             {
  410.                score = Math.floor(300 * Math.random()) * 10;
  411.                updatescore();
  412.             }
  413.             play_chewyhitsthetop_sound();
  414.             lives = 0;
  415.             _parent.gamestate = GAMESTATE_GAME_OVER_FADE;
  416.             timeinstate = 0;
  417.             _parent.life0._visible = false;
  418.             _parent.life1._visible = false;
  419.             _parent.life2._visible = false;
  420.          }
  421.          break;
  422.       case GAMESTATE_GAME_OVER_FADE:
  423.          if(_parent.floorsoundplaying)
  424.          {
  425.             stop_floorraising_noise();
  426.             _parent.floorsoundplaying = false;
  427.          }
  428.          timeinstate += _parent.delta;
  429.          var fadeamount = 100 - 100 * timeinstate / 20;
  430.          if(fadeamount < 0)
  431.          {
  432.             fadeamount = 0;
  433.          }
  434.          _alpha = fadeamount;
  435.          var b = 0;
  436.          while(b < MAX_BAGS)
  437.          {
  438.             _parent["bag" + b]._alpha = fadeamount;
  439.             b++;
  440.          }
  441.          var f = 0;
  442.          while(f < MAX_FLAMES)
  443.          {
  444.             _parent["flame" + f]._alpha = fadeamount;
  445.             f++;
  446.          }
  447.          var c = 0;
  448.          while(c < MAX_CHEWITS)
  449.          {
  450.             _parent["chewit" + c]._alpha = fadeamount;
  451.             _parent["chewitscore" + c]._alpha = _parent["chewitscore" + c].startalpha * fadeamount / 100;
  452.             c++;
  453.          }
  454.          _parent.comboscore._alpha = _parent.comboscore.startalpha * fadeamount / 100;
  455.          _parent.bonusbomb._alpha = _parent.bonusbomb.startalpha * fadeamount / 100;
  456.          if(fadeamount == 0)
  457.          {
  458.             mouse.show();
  459.             _parent.gamestate = GAMESTATE_GAME_OVER_HISCORE_ENTRY;
  460.             timeinstate = 0;
  461.             _parent.scoretext._visible = false;
  462.             _parent.floor_mc._visible = false;
  463.             _parent.sky_mc._visible = false;
  464.          }
  465.          break;
  466.       case GAMESTATE_GAME_OVER_HISCORE_ENTRY:
  467.          _parent.attachMovie("hiscoreentry_mc","hiscoreentry",40);
  468.          _parent.hiscoreentry.myname.text = "";
  469.          _parent.gamestate = GAMESTATE_GAME_OVER;
  470.          timeinstate = 0;
  471.          break;
  472.       case GAMESTATE_GAME_OVER_HISCORES:
  473.          var thename = _parent.hiscoreentry.myname.text;
  474.          _parent.attachMovie("hiscorescreen_mc","hiscorescreen",40);
  475.          _parent.hiscorescreen._x = 0;
  476.          _parent.hiscorescreen._y = 0;
  477.          _parent.hiscorescreen._visible = true;
  478.          var HISCORE_START_X = 38;
  479.          var HISCORE_START_Y = 107;
  480.          var HISCORE_DELTA_Y = 30;
  481.          var MAX_HIGHSCORES = 10;
  482.          var h = 0;
  483.          while(h < MAX_HIGHSCORES)
  484.          {
  485.             _parent.hiscorescreen.attachMovie("highscore_mc","hiscore" + h,42 + h);
  486.             _parent.hiscorescreen["hiscore" + h]._x = HISCORE_START_X;
  487.             _parent.hiscorescreen["hiscore" + h]._y = HISCORE_START_Y + HISCORE_DELTA_Y * h;
  488.             _parent.hiscorescreen["hiscore" + h].score.text = hiscores[h][1];
  489.             if(hiscores[h][0] != "")
  490.             {
  491.                _parent.hiscorescreen["hiscore" + h].position.text = h + 1 + ".";
  492.             }
  493.             else
  494.             {
  495.                _parent.hiscorescreen["hiscore" + h].position.text = "";
  496.             }
  497.             _parent.hiscorescreen["hiscore" + h].name.text = hiscores[h][0];
  498.             _parent.hiscorescreen["hiscore" + h].score.embedFonts = true;
  499.             _parent.hiscorescreen["hiscore" + h].name.embedFonts = true;
  500.             _parent.hiscorescreen["hiscore" + h].position.embedFonts = true;
  501.             h++;
  502.          }
  503.          var YOUR_SCORE_GAP = 9;
  504.          _parent.hiscorescreen.attachMovie("highscore_mc","hiscore-1",41);
  505.          _parent.hiscorescreen["hiscore-1"]._x = HISCORE_START_X;
  506.          _parent.hiscorescreen["hiscore-1"]._y = HISCORE_START_Y + HISCORE_DELTA_Y * hiscores.length + YOUR_SCORE_GAP;
  507.          if(thename == "")
  508.          {
  509.             thename = "(you)";
  510.          }
  511.          _parent.hiscorescreen["hiscore-1"].position.text = positiontext;
  512.          myformat1 = _parent.hiscorescreen["hiscore-1"].position.getTextFormat();
  513.          myformat1.color = 65535;
  514.          _parent.hiscorescreen["hiscore-1"].position.embedFonts = true;
  515.          _parent.hiscorescreen["hiscore-1"].position.setTextFormat(myformat1);
  516.          _parent.hiscorescreen["hiscore-1"].position.embedFonts = true;
  517.          _parent.hiscorescreen["hiscore-1"].name.text = thename;
  518.          myformat1 = _parent.hiscorescreen["hiscore-1"].name.getTextFormat();
  519.          myformat1.color = 65535;
  520.          _parent.hiscorescreen["hiscore-1"].name.embedFonts = true;
  521.          _parent.hiscorescreen["hiscore-1"].name.setTextFormat(myformat1);
  522.          _parent.hiscorescreen["hiscore-1"].name.embedFonts = true;
  523.          _parent.hiscorescreen["hiscore-1"].score.text = score;
  524.          myformat1 = _parent.hiscorescreen["hiscore-1"].score.getTextFormat();
  525.          myformat1.color = 65535;
  526.          _parent.hiscorescreen["hiscore-1"].score.embedFonts = true;
  527.          _parent.hiscorescreen["hiscore-1"].score.setTextFormat(myformat1);
  528.          _parent.hiscorescreen["hiscore-1"].score.embedFonts = true;
  529.          _parent.gamestate = GAMESTATE_GAME_OVER;
  530.          timeinstate = 0;
  531.    }
  532. }
  533.